<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>商家缩略图编辑</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<jsp:include page="/pub.jsp"></jsp:include>

<script type="text/javascript">
/* 单文件上传：适合传封面图 */
$(function(){
    var options = {
        url : "${pageContext.request.contextPath}/aotemaiShop/uploadThumbnail",
        dataType : "json",
        type : "post",
        success : function(j){
        	if(j.success){
        		//$("#attachmentid").val(j.msg);
        		$("#pictureScan").attr("src",'${pageContext.request.contextPath}'+j.obj);	//图片预览
        		$("#pictureScan").attr("picturePath",j.obj);
        		$("#msgshow").html(j.msg);		//图片上传后的提示消息
        	}else{
        		$("#msgshow").html(j.msg);
        	}
        }
    };
    $("#pic").change(function(){
       $("#upload").ajaxSubmit(options)
    });
	
	var  updateThumbnail = function(){
		var id = '${aotemaiShop.id }';
		var path = $("#pictureScan").attr("picturePath");
		$.messager.confirm('确认','您确认想要更新商家的封面图吗？',function(r){
		    if (r){
				$.post('${pageContext.request.contextPath}/aotemaiShop/updateThumbnail/'+id+'?thumbnail='+path, function(j) {
					$.messager.show({
						title : '提示',
						msg : j.msg,
						timeout : 5000,
						showType : 'slide'
					});
				}, 'json');
		    }    
		});
	};
	
	$('#updateThumbnail').on('click',function(){
		updateThumbnail();
	});
	
	
});
</script>

</head>

<body>
	<!-- 商家缩略图上传  -->
	<form id="upload" method="post" enctype="multipart/form-data">
		<table style="width: 100%;" class="table table-hover table-condensed">
			<tr>
				<th rowspan="2">图标/图片</th>
				<td >
					<input id="pic" type="file" name="pic" style="width:100%;">
				</td>
				<th rowspan="2">预览</th>
				<td rowspan="2">
					<img id="pictureScan" picturePath="" src="${pageContext.request.contextPath}${aotemaiShop.thumbnail }" onclick="javascript:window.open(this.src)" style="cursor:hand" width="90em" height="120em" border="0" />
				</td>
			</tr>
			<tr>
				<td>
					<span>只允许上传小于1Mb的图片</span><br>
					<span id="msgshow" style="color:blue;"></span>
				</td>
			</tr>
		</table>
		<div align="center"><a href="javascript:void(0);" id="updateThumbnail" class="easyui-linkbutton c1" style="width:120px">提交</a></div>
	</form>
</body>
</html>